package com.jinyi.wwdeng.utils.event

import com.jinyi.base.network.IRequestCallback
import com.jinyi.base.network.NetworkUtils
import com.jinyi.base.utils.log.HHLog
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.network.HttpBaseParams.addCommonParams
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/5/8 13:44
 * @Annotation：事件埋点
 */
object TrackEventUtils {

    /**
     * 添加事件埋点
     * 事件类型命名规则：
     *    1、page：                 Henecredit_xxx_start        /  Henecredit_xxx_end
     *    2、click：                Henecredit_xxx_click
     *    3、dialog：               Henecredit_xxx_show          /  Henecredit_xxx_dismiss
     *    4、authentication form：  Henecredit_paramName_form
     */
    fun logEvent(eventName: String,remark: String){
        var eventType = eventName
        if(!eventType.startsWith("Henecredit_")){
            eventType = "Henecredit_$eventType"
        }
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_TRACK_EVENT)
            put("type",eventType.uppercase())//事件类型
            put("remark",remark)//事件备注
        }
        HHLog.e("logEvent>>>>>>>${params}")
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
            }
            //请求完成
            override fun onRequestFinish() {
            }
        })
    }
}